package com.xcity.game.combat.attr;

/**
 * 战斗属性所有类型
 * @author yang.li
 *
 */
public enum CombatAttributeType implements CombatAttributeFilter, CombatAttributeFormatter {

	/** 物攻 0 */
	ATTACK_POWER(),
	/** 法攻 1 */
	MAGIC_POWER(),
	/** 物防 2 */
	DEFENSE(),
	/** 法防 3 */
	MAGIC_DEFENSE(),
	/** 暴击 4 % */
	CRIT(CombatAttributeFormatter.Formatters.THOUSANDFOLD_PERCENT, 0.001f),
	/** 韧性 5 */
	AVOID_CRIT(CombatAttributeFormatter.Formatters.THOUSANDFOLD_PERCENT, 0.001f),
	/** 生命值 6 */
	HP(),
	/** 出手速度 7 */
	ATTACK_SPEED(),
	/** 暴击伤害 8 % */
	@Deprecated CRIT_DAMAGE(CombatAttributeFormatter.Formatters.PERCENT, 1),
	/** 能量 9 */
	MP(),
	/** 最大生命值 10 */
	MAX_HP(),
	/** 最大能量值 11 */
	MAX_MP(),
	//---v2---
	/** 闪避 12 % */
	DODGE(CombatAttributeFormatter.Formatters.THOUSANDFOLD_PERCENT, 0.001f),
	/** 抵抗 13 */
	RESIST(0.001f),
	/** 物攻命中 14 % */
	HIT_RATE(CombatAttributeFormatter.Formatters.THOUSANDFOLD_PERCENT, 0.001f),
	/** 法攻命中 15 % */
	MAGIC_HIT_RATE(CombatAttributeFormatter.Formatters.THOUSANDFOLD_PERCENT, 0.001f),
	//---v2---
	;
	
	public final CombatAttributeFilter filter;
	public final CombatAttributeFormatter formatter;
//	public final CombatAttributeDerive derive; // 二维属性衍生器（一维->二维）
	public final float scale; // 缩放比例（暴击、韧性、闪避、抵抗、物攻命中、法攻命中存储的为千倍值，战斗计算时需除以1000）
	
	public static final CombatAttributeType[] vals = values();
	public static final int MASK_FULL = 0xffff; // 16 bits
	
	CombatAttributeType(/*CombatAttributeDerive derive*/) {
		this(CombatAttributeFilter.Filters.ADD, CombatAttributeFormatter.Formatters.PLAIN/*, derive*/, 1);
	}
	
	CombatAttributeType(float scale) {
		this(CombatAttributeFormatter.Formatters.PLAIN, scale);
	}
	
	CombatAttributeType(CombatAttributeFormatter formatter/*, CombatAttributeDerive derive*/, float scale) {
		this(CombatAttributeFilter.Filters.ADD, formatter/*, derive*/, scale);
	}
	
	CombatAttributeType(CombatAttributeFilter filter, CombatAttributeFormatter formatter/*, CombatAttributeDerive derive*/, float scale) {
		this.filter = filter;
		this.formatter = formatter;
//		this.derive = derive;
		this.scale = scale;
	}
	
	public static CombatAttributeType forType(int type) {
		CombatAttributeType[] _vals = vals;
		return type >= 0 && type < _vals.length ? _vals[type] : null;
	}
	
	public static int length() {
		return vals.length;
	}
	
	@Override
	public Object format(float value) {
		return formatter.format(value);
	}
	
	@Override
	public float doFilter(float value, float factor) {
		return filter.doFilter(value, factor);
	}
	
}
